angular.module('meHistoryOrderDetailservices', [])

  .factory('MeHistoryOrderDetail', function ($resource, $rootScope, ENV) {

    //设置访问接口路径
    var APIUrl = ENV.api;

    //访问获取用户信息的接口
    var getWineListByIdResource = $resource(APIUrl + "meHistoryWine/getWineListById.do");
    var addNewRecommendWineResource = $resource(APIUrl + "meHistoryWine/addNewRecommendWine.do");


    var mrwId;
    var orderDetailJson;
    var addStatus;
    var orderWineList;
    var insertNewOrderJson;

    return {

      // 设置历史酒单的Id
      setMrwId : function (mrw_id){
        mrwId = mrw_id;
      },

      getMrwId : function (){
        return mrwId;
      },

      //获取历史酒单详情
      getOrderDetail : function (mrwId,memberId){
        getWineListByIdResource.save(
          {
            mrw_id : mrwId,
            member_id : memberId
          },
          function (data) {
            orderDetailJson = data;
            $rootScope.$broadcast('Me.getOrderDetail');
          }
        );
      },
      getOrderDetailJson : function (){
        return orderDetailJson;
      },

      //设置添加酒款标识
      setAddMoreWineStatus : function (status){
        addStatus = status;
      },
      //获取添加酒款标识
      getAddMoreWineStatus : function (){
        return addStatus;
      },
      setOrderWineList: function (wineList) {
        orderWineList = wineList;
      },
      getOrdrWineList: function () {
        return orderWineList;
      },

      insertNewOrder : function (id,name,list){
        addNewRecommendWineResource.save(
          {
            member_id: id,
            mrw_name : name,
            wineList : list
          },
          function (data) {
            insertNewOrderJson = data;
            $rootScope.$broadcast('Me.insertNewOrder');
          }
        );
      },

      getInsertNewOrder : function(){
        return insertNewOrderJson;
      }




    }

  });
